package com.design.cjm.creational.singleton.example4;

/**
 * 双重锁单例模式
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/9/27
 * @Version 1.0
 */
public class Singleton {

    // 增加线程间的可见性
    private volatile static Singleton singleton = null;

    private Singleton() {
    }

    // 方法内部加锁
    public static Singleton getSingleton() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
